<?php
$user = $_SESSION["adminLoggedUserName"];

$alias = trim($_POST["alias"]);
$name = trim($_POST["name"]);
$description = trim($_POST["description"]);
$keywords = trim($_POST["keywords"]);

switch ($_POST["operation"])
{
	// Add
	case "add":
		$operationName = "Inserción";
		$query = "";
		break;
	// Edit
	case "edit":
		$operationName = "Modificación";
		$query = "UPDATE sections SET ".
				 		 "modified = NOW(), ".
						 "modifiedBy = '$user', ".
						 "alias = '".$db->escapeString(utf8_decode($alias))."', ".
						 "name = '".$db->escapeString(utf8_decode($name))."', ".
						 "description = '".$db->escapeString(utf8_decode($description))."', ".
						 "keywords = '".$db->escapeString(utf8_decode($keywords))."' ".
						 "WHERE id = '".$_POST["id"]."'";
		break;
	// Default
	default:
		echo "ko|No se ha especificado ninguna operación.";
		exit;
}

if (!$db->runQuery($query)) {
	echo "ko|Error de MySQL: ".$db->getErrorDescription();
	exit;
}

echo "ok|".$operationName." correcta.";
exit;
?>
